  <div id='add_todo_item_label_<%=todo.id%>' class=add_todo_item>
  <%if (not @project.use_permission  or @project.use_permission.nil?) or (@project.use_permission and @cur_user.has_permission?("prj_" + @project.id.to_s + "_todo_new"))%>
    <%=link_to "Add an item".t,"#",:class=>'admin',:onclick=>"Element.hide('add_todo_item_label_#{todo.id}');Element.show('add_todo_item_form_#{todo.id}')"%>
   <%end%>
  </div>

  <%form_remote_for :todo_item,:url=>{:action=>'add_todo_item'} do |f|%>
  <div id='add_todo_item_form_<%=todo.id%>' style="display:none" class="add_todo_item">
    <%=f.hidden_field "todo_id",:value=>todo.id%>
    <%="Enter a to-do item".t%><br/>
    <%=f.text_area "name",:rows=>4,:cols=>50,:maxlength=>160%>
    <%=hidden_field_tag "project_id",@project.id%>
    <table style="font-size:12px;width:450px;">
    <tr><td width=50% colspan=2>
    <%="Who is responsible?".t%>:</br>
    <select name='todo_item[user_id]'>
    <%if todo.milestone%>
    <%=options_from_collection_for_select @project.users,"id","name"%>
    <%else%>
    <option><%="Anyone".t%></option>
    <option value=<%=@cur_user.id%>><%="Me".t%>(<%=@cur_user.name%>)</option>
    <option>------------</option>
    <%=options_from_collection_for_select @project.users - [@cur_user],"id","name"%>
    <%end%>
    </select>
    </td>
    <td>
    <%="What's the priority of this item?".t%>:</br>
    <%TODO_PRIOR.to_a.each do |p|%>
      <span class="prior p_<%=p[0]%>">
      <%=f.radio_button "prior",p[0],:checked => (p[0] == 4 ? true : false) %>
      </span>
    <%end%>
    </td></tr>
    <!-- appendix for todo date start-->
    <%if todo.milestone%>

    <%day_distance = ((todo.milestone.due_at - todo.milestone.started_at)/(24*60*60)).to_i%>
             <%#distance = 14%>
               <%#unless todo.milestone.nil?%>
                 <%#unless  todo.milestone.due_at.nil? %>
                   <%#distance = ((todo.milestone.due_at - Time.now)/(24*60*60)).to_i + 1%>
                <%#end%>
               <%#end%>
             <%#day_distance = distance < 14 ? distance:14%>
    <tr><td><%="From".t%>:</td>
       <td>
       <%if Time.now > todo.milestone.started_at%>
       <%=radio_button_tag"from","today",true,:onclick=>"$('start_at_#{todo.id}').disabled = true"%><%="Today".t%>[<%=Time.now.strftime("%m/%d")%>]
       <%else%>
       <%=radio_button_tag"from","today",true,:onclick=>"$('start_at_#{todo.id}').disabled = true"%><%="Milestone start".t%>[<%=todo.milestone.started_at.strftime("%m/%d")%>]
       <%end%>
       </td><td>
                <%=radio_button_tag"from","user_choice",false,:onclick=>"$('start_at_#{todo.id}').disabled = false"%>
                <select id='start_at_<%=todo.id%>' name='from_days' disabled=true onchange="removeDue(this.selectedIndex);">
                  <%(1).upto(day_distance) do |i|%>
                    <%next if i == 0 %>
                    <option value=<%=i%><%=(i==1 ? " selected":"")%>>
                    [<%=i.days.since(todo.milestone.started_at).strftime("%Y/%m/%d")%>]
                    <%=i.abs%><%=" days ".t%><%=(i>0 ? "later":"ago").t%>
                    </option> 
                  <%end%>
                </select>
             </td>
          </tr>
          <tr>
             <td><%="To".t%>:</td>
             <td>
             <%=radio_button_tag"to","next_day",true,:onclick=>"$('due_at_#{todo.id}').disabled = true"%><%="Next day".t%>(<%="until finished".t%>)</td>
             <td>
                <%=radio_button_tag"to","user_choice",false,:onclick=>"$('due_at_#{todo.id}').disabled = false"%>
                <select id='due_at_<%=todo.id%>' name='to_days' disabled=true>
                  <%1.upto(day_distance) do |i|%>
                    <%next if i == 0 %>
                    <option value=<%=i%><%=(i==1 ? " selected":"")%>>
                    [<%=i.days.since(todo.milestone.started_at).strftime("%Y/%m/%d")%>]
                    <%=i.abs%><%=" days ".t%><%=(i>0 ? "later":"ago").t%>
                    </option> 
                  <%end%>
                </select>
           </td>
       </tr>
    <script>
      function removeDue(i){
        for(j=0;j<=<%=day_distance%>;j++){
            try {
              $('due_at_<%=todo.id%>').remove(0);
            } catch (e){
              alert(e);
            }
        }
         for(j=(i+1);j<=<%=day_distance%>;j++){
            var o = document.createElement('option');
             o.text  = $('start_at_<%=todo.id%>').options[j].text;
             o.value = $('start_at_<%=todo.id%>').options[j].value;
           try {
             $('due_at_<%=todo.id%>').add(o,null);
            } catch(ex) {
             $('due_at_<%=todo.id%>').add(o); // IE only
            }
         } 
      }
    </script>
    <%end%>
    <!-- appendix for todo data end-->
    </table>
    <hr size=1>
    <div id=add_todo_action_<%=todo.id%>>
    <%=submit_tag "Add this item".t,:onclick=>"Element.hide('add_todo_action_#{todo.id}');Element.show('add_todo_indicator_#{todo.id}')"%> <%="or".t%> 
    <%=link_to"I'm done adding items".t,"#",:class=>'admin',:onclick=>"Element.show('add_todo_item_label_#{todo.id}');Element.hide('add_todo_item_form_#{todo.id}');"%>
    </div>
    <%end%>
    <div id=add_todo_indicator_<%=todo.id%> style="display:none;height:28px;"><%=image_tag"indicator.gif"%></div>
  </div> <!--add_todo_item_form-->
